"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodeScanAction = void 0;
const chalk_1 = require("chalk");
const ui_1 = require("../lib/ui");
const abstract_action_1 = require("./abstract.action");
class CodeScanAction extends abstract_action_1.AbstractAction {
    handle(inputs, options) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                yield this.runBuild(inputs, options);
            }
            catch (err) {
                if (err instanceof Error) {
                    console.log(`\n${ui_1.ERROR_PREFIX} ${err.message}\n`);
                    console.log(err);
                }
                else {
                    console.error(`\n${chalk_1.default.red(err)}\n`);
                    console.log(err);
                }
            }
        });
    }
    runBuild(inputs, options, isDebugEnabled = false, onSuccess) {
        return __awaiter(this, void 0, void 0, function* () {
            let codeScan = (() => { });
            try {
                codeScan = require('cpaas-front-util/bin/codeScan');
            }
            catch (e) {
                console.error(`需要安装 cpaas-front-util： yarn add -W -D cpaas-front-util`);
                process.exit(1);
                return;
            }
            if (codeScan.default) {
                codeScan = codeScan.default;
            }
            // 调用 cpaas-front-util 扫描
            yield codeScan();
        });
    }
}
exports.CodeScanAction = CodeScanAction;
